/**
 * 
 */

package propertyeditor;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import com.e885.log.E885Logger;

/**
 * @author Eric.Kao(gau168.gau@msa.hinet.net)
 * @version 1.0
 * @company E885 Group
 * @copyright Copyright (c) 2001-2008
 */

public class PropertyEditorSimpleFormController extends SimpleFormController
{
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.springframework.web.servlet.mvc.BaseCommandController#initBinder(javax.servlet.http.HttpServletRequest,
	 *      org.springframework.web.bind.ServletRequestDataBinder)
	 */
	@Override
	protected void initBinder( HttpServletRequest request, ServletRequestDataBinder binder ) throws Exception
	{
		super.initBinder( request, binder );
		
		binder.registerCustomEditor( User.class, new MyPropertyEditor() );
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(java.lang.Object)
	 */
	@Override
	protected ModelAndView onSubmit( Object command ) throws Exception
	{
		E885Logger.testLog.debug( "execute method onSubmit()" );
		
		MyCommand myCommand = ( MyCommand )command;
		
		User user = myCommand.getUser();

		Map< String, String > map = new HashMap< String, String >();
		map.put( "firstName", user.getFirstName() );
		map.put( "lastName", user.getLastName() );

		return new ModelAndView( getSuccessView(), map );
	}
}
